package com.strato.mvc.menu.v1_0_0;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

public class Menu implements Serializable,Comparable<Menu>{

	private static final long serialVersionUID = -3753868101767398436L;

	private String path;
	
	private String text;
	
	private String url;
	
	private String icon;
	
	private boolean includeContext;
	
	private int order;
	
	private SortedMap<String,Menu> subMenus;

	private String nodeName;
	
	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getNodeName() {
		return nodeName;
	}

	public void setNodeName(String nodeName) {
		this.nodeName = nodeName;
	}

	public int getOrder() {
		return order;
	}

	public void setOrder(int order) {
		this.order = order;
	}

	public String getUrl() {
		return url;
	}

	public String getFullUrl(String context) {
		if(!includeContext){
			return context+url;
		}else{
			return url;
		}
	}
	
	public void setUrl(String url) {
		this.url = url;
	}

	public boolean isIncludeContext() {
		return includeContext;
	}

	public void setIncludeContext(boolean includeContext) {
		this.includeContext = includeContext;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public Map<String, Menu> getSubMenus() {
		return subMenus;
	}

	public List<Menu> getSortedSubMenus() {
		if(subMenus==null){
			return null;
		}
		List<Menu> menus = new ArrayList<Menu>(subMenus.values());
		Collections.sort(menus);
		return menus;
	}

	public void setSubMenus(SortedMap<String, Menu> subMenus) {
		this.subMenus = subMenus;
	}

	public Menu getSubMenu(String name) {
		if(subMenus==null){
			return null;
		}
		return subMenus.get(name);
	}

	public void addSubMenu(String name, Menu sub) {
		if(subMenus==null){
			subMenus=new TreeMap<String,Menu>();
		}
		subMenus.put(name,sub);
	}

	@Override
	public int compareTo(Menu o) {
		return order-o.order;
	}
}
